package de.mhu.mandalaui.actions;

import java.io.PrintWriter;
import java.util.LinkedList;

import de.mhu.mandalaui.Response;
import de.mhu.mandalaui.bind.Element;

public class InlineAction extends Action {

	private LinkedList<Object> activities = new LinkedList<Object>();
	private boolean isFunction = true;
	
	public InlineAction(Object...act) {
		if (act != null) {
			for (Object a : act)
				activities.add(a);
		}
	}
	@Override
	public void renderFunctionImplementation(PrintWriter out) {
		if (isFunction) out.println("function(data) {");
		for (Object act  : activities) {
			if (act instanceof Element) {
				Element ele = (Element)act;
				ele.renderBindCall(out);
			} else
				out.print(act);
		}
		if (isFunction) out.println("}");
	}

	public void doRegister(Response response) {
		for (Object p : activities) {
			if (p instanceof Element) {
				response.registerAttribute((Element)p);
			}
		}
	}
	public boolean isFunction() {
		return isFunction;
	}
	public void setFunction(boolean isFunction) {
		this.isFunction = isFunction;
	}

}
